// pages/home/home.js
const API = require('../../http/API')
const http = require('../../http/http')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerPic: [],
    subMenuList: [
      {
        id: 0,
        text: "免费教程",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h9-b_1806.png"
      },
      {
        id: 1,
        text: "专业课程",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h12-g_1806.png"
      },
      {
        id: 2,
        text: "大触直播",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h2-p_2212.png"
      },
      {
        id: 3,
        text: "教程兑换",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h10-o_1806.png"
      },
      {
        id: 4,
        text: "学员成长",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h11-c_2212.png"
      },
      {
        id: 5,
        text: "每日一画",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h11-c_1811.png"
      },
      {
        id: 6,
        text: "素材下载",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h14-r_2212.png"
      },
      {
        id: 7,
        text: "社区问答",
        image: "https://assets-cdn.lanqb.com/imgv3_m/images-icon/submenu/h5-p_2211.png"
      }
    ],
    daChuContent1: [],
    daChuContent2: [],
    // 热门教程
    hotCourse: [],
    // 问答专区
    questions: [],
    // 素材下载
    materialDownload: [],
    footerPic: [
      {
        id: 0,
        image: "https://assets-cdn.lanqb.com/image/footer/footer-icon1_124x47.png"
      },
      {
        id: 1,
        image: "https://assets-cdn.lanqb.com/image/footer/footer-icon5@2x.png"
      },
      {
        id: 2,
        image: "https://assets-cdn.lanqb.com/image/footer/footer-icon2@2x.png"
      },
      {
        id: 3,
        image: "https://assets-cdn.lanqb.com/image/footer/footer-icon3@2x.png"
      },
      {
        id: 4,
        image: "https://xyt.xcc.cn/img/icon/icon8.png"
      }
    ],
    isShow: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getBannerPic()
    // 大触直播
    this.getDaChu()
    // 热门教程
    this.getHotCourse()
    // 问答专区
    this.getQuestions()
    // 素材下载
    this.getMaterialDownload()
  },
  // 获取轮播图
  getBannerPic() {
    http(API.banner, {
      type: "m",
      local_code: 10,
      order:"weight",
      limit: 6,
    }).then(res => {
      console.log(res.data);
      this.setData({ bannerPic: res.data.data })
    })
  },
  // 大触直播
  // https://m.lanqb.com/api/daniu?link=paging&live=3&is_live=1&limit=5&page=1
  getDaChu() {
    http(API.dachu, {
      link: "paging",
      live: 3,
      is_live: 1,
      limit: 5,
      page: this.data.page,
    }).then(res => {
      // console.log(res.data);
      let arr = res.data.course.data.slice(1, 3)
      let arr1 = res.data.course.data.slice(0, 1)
      this.setData({ daChuContent1: arr1 })
      this.setData({ daChuContent2: arr })
    })
  },
  // 热门教程
  getHotCourse() {
    http(API.hotcourse).then(res => {
      this.setData({ hotCourse: res.data.slice(0, 4) })
    })
  },
  // 问答专区
  getQuestions() {
    http(API.questions,{
      limit:4,
      teacher_show:1
    }).then(res => {
      this.setData({ questions: res.data.slice(0, 3) })
    })
  },
  // 素材下载
  getMaterialDownload() {
    http(API.materialDownload,{
      type:"sucai",
      page:1,
    }).then(res => {
      this.setData({ materialDownload: res.data.data.slice(0, 3) })
    })
  },
  skipClick(e) {
    console.log(e.currentTarget.id);
    if (e.currentTarget.id == 2) {
      wx.switchTab({
        url: '/pages/dachu/dachu',
      })
    }
  },
  playChange() {
    this.setData({ isShow: false })
  },
  pauseChange() {
    this.setData({ isShow: true })
  },
  toDachuClick() {
    wx.switchTab({
      url: '/pages/dachu/dachu',
    })
  },
  tojiaochengClick() {
    wx.switchTab({
      url: '/pages/course/course',
    })
  }
})